<?php

namespace app\api\controller;

use app\ApiBaseController;

class Resources extends ApiBaseController
{
    /**
     * 批量获取资源
     */
    public function getResourcesList()
    {
        $title = $this->request->param('keywords/s');
        $data = \app\admin\model\Resources::where('status', 1)
            ->whereLike('title','%'.$title.'%')
            ->hidden(['status','update_time','images'])
            ->select();
        if ($data->isEmpty()){
            return result(1,'', []);
        }
        return result(0, '', $data);
    }

    /**
     * 获取单个资源
     */
    public function getResources()
    {
        $id = $this->request->param('id/d');
        $data = \app\admin\model\Resources::where(['status' => 1, 'id' => $id])->hidden(['status','update_time'])->find();
        if (empty($data)){
            return result(1,'记录不存在');
        }
        try {
            if (empty($data['images'])){
                $data['images'] = [];
            }else{
                $data['images'] = explode('|', $data['images']);
            }
        }catch (\Exception $e){
            return result(1, $e->getMessage());
        }
        return result(0, '', $data);
    }
}